/**********************************************************************\

 Copyright 2012 Diggory Blake

 This file is part of klip-engine

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.

\**********************************************************************/
#pragma once

#include <type_traits>

template<typename T> struct add_target_const {
	typedef typename std::conditional<
		std::is_pointer<T>::value,
		const typename std::remove_pointer<T>::type*,
		T
	>::type type;
};

class kBase {
private:

	// Copying and assignment not allowed!
	kBase(const kBase& other);
	kBase& operator=(const kBase& other);

protected:
	inline kBase() { }

public:
	virtual ~kBase();
	template<typename T> bool isA() {
		return dynamic_cast<T>(this) != 0;
	}
	template<typename T> T as() {
		return dynamic_cast<T>(this);
	}
	template<typename T> typename add_target_const<T>::type as() const {
		return dynamic_cast<typename add_target_const<T>::type>(this);
	}
};
